<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title></title>
		<link rel="stylesheet" type="text/css" href="js/elementUI/index.css"/>
		<link rel="stylesheet" href="css/main.css">
		
	</head>
	<body>
		<div class="main" id="app">
			<div class="formwrap">
				<el-form  :model="form" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">
				  <el-form-item label="证书名称" prop="subject">
						<el-input v-model="form.subject"></el-input>
				  </el-form-item>
				  <el-form-item label="秘钥名称" prop="privateAlias">
				  		<el-input v-model="form.privateAlias"></el-input>
				  </el-form-item>
				  <el-form-item label="秘钥口令" prop="keyPass">
				  		<el-input v-model="form.keyPass"></el-input>
				  </el-form-item>
				  <el-form-item label="秘钥库口令" prop="storePass">
				  		<el-input v-model="form.storePass"></el-input>
				  </el-form-item>
				  <el-form-item label="license有效期起始时间" prop="issuedTime">
						<el-date-picker type="datetime" placeholder="选择license有效期起始时间" v-model="form.issuedTime"></el-date-picker>
				  </el-form-item>
				  <el-form-item label="license有效期截止时间" prop="expiryTime">
				  		<el-date-picker type="datetime" placeholder="选择license有效期截止时间" v-model="form.expiryTime"></el-date-picker>
				  </el-form-item>
				  <p>校验参数</p>
				  <el-form-item label="客户机IP" prop="ipAddress" style="width: 100%;">
				  		<el-input v-model="form.ipAddress"></el-input>
				  </el-form-item>
				  <el-form-item label="客户机MAC地址" prop="macAddress" style="width: 100%;">
				  		<el-input v-model="form.macAddress"></el-input>
				  </el-form-item>
				  <el-form-item label="客户机CPU序列号" prop="cpuSerial" style="width: 100%;">
				  		<el-input v-model="form.cpuSerial"></el-input>
				  </el-form-item>
				  <el-form-item label="客户机主板序列号" prop="mainBoardSerial" style="width: 100%;">
				  		<el-input v-model="form.mainBoardSerial"></el-input>
				  </el-form-item>
				  <el-form-item style="width: 100%;">
					<el-button type="primary" @click="scxk('ruleForm')" :disabled="issc">生成许可</el-button>
					<el-button type="primary" @click="xzxk()" :disabled="isdownload">下载许可</el-button>
				  </el-form-item>
				</el-form>
			</div>
		</div>
		<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/elementUI/index.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			let vm = new Vue({
				el: '#app',
				data() {
					return{
						ip:"",
						isdownload:true,
						issc:false,
						form: {
						   subject:"", //#证书subject
						   privateAlias:"",  //#秘钥别名       
						   keyPass:"",    //#秘钥口令
						   storePass:"",   //#秘钥库口令
						   issuedTime:"",  //#license有效期起始时间  
						   expiryTime:"",   //#license有效期截止时间 
						   ipAddress:"",      //#客户机ip
						   macAddress:"",  //#客户机mac地址   
						   cpuSerial:"",         //#客户机cpu序列号
						   mainBoardSerial:""    //#客户机主板序列号
						},
						setdata:{
							subject:"", //#证书subject
							privateAlias:"",  //#秘钥别名       
							keyPass:"",    //#秘钥口令
							storePass:"",   //#秘钥库口令
							issuedTime:"",  //#license有效期起始时间  
							expiryTime:"",  //#license有效期截止时间,
							licenseCheckModel:{
								ipAddress:[],
								macAddress:[],
								cpuSerial:"",
								mainBoardSerial:"",
							} 
						},
						rules: {
						  subject: [
							{ required: true, message: '请输入证书名称', trigger: 'blur' },
						  ],
						  privateAlias: [
						 	{ required: true, message: '请输入秘钥别名', trigger: 'blur' },
						  ],
						  keyPass: [
						  	{ required: true, message: '请输入秘钥口令', trigger: 'blur' },
						  ],
						  storePass: [
						  	{ required: true, message: '请输入秘钥库口令', trigger: 'blur' },
						  ],
						  privateKeysStorePath: [
						  	{ required: true, message: '请输入秘钥库文件文件', trigger: 'blur' },
						  ],
						  ipAddress: [
						  	{ required: true, message: '请输入客户机ip', trigger: 'blur' },
						  ],
						  macAddress: [
						  	{ required: true, message: '请输入客户机mac地址', trigger: 'blur' },
						  ],
						  issuedTime: [
							{ type: 'date', required: true, message: '请选择license有效期起始时间', trigger: 'change' }
						  ],
						  expiryTime: [
							{ type: 'date', required: true, message: '请选择license有效期截止时间', trigger: 'change' }
						  ],
						  
						}
					}
				},
				computed: {},
				created() {
					this.ip=window.location.origin;
				},
				mounted(){
					let _this=this;
					$('document').ready(function () {
					});	
				}, 
				methods: {	
					scxk(formName) {
						this.$refs[formName].validate((valid) => {
						  if (valid) {
						  	debugger;
							//拼接参数
							this.setdata.subject=this.form.subject;
							this.setdata.privateAlias=this.form.privateAlias;
							this.setdata.keyPass=this.form.keyPass;
							this.setdata.storePass=this.form.storePass;
							this.setdata.issuedTime=this.dateFm(this.form.issuedTime);
							this.setdata.expiryTime=this.dateFm(this.form.expiryTime);
							this.setdata.licenseCheckModel.ipAddress.push(this.form.ipAddress);
							this.setdata.licenseCheckModel.macAddress.push(this.form.macAddress);
							this.setdata.licenseCheckModel.cpuSerial=this.form.cpuSerial;
							this.setdata.licenseCheckModel.mainBoardSerial=this.form.mainBoardSerial;
							//请求接口
							axios.post(this.ip+"/license/generateLicense",this.setdata).then(res=>{
								if(res.data.code==1){
									this.$message.success(res.data.msg);
									this.isdownload=false;
									this.issc=true;
								}else{
									this.$message.error(res.data.msg);
									this.issc=false;
								}
							});
						  } else {
							console.log('error submit!!');
							return false;
						  }
						});
					},
					xzxk() {
						window.open(this.ip+"/license/download");
					},
					dateFm(date){
						var YY=date.getFullYear();
						var MM=date.getMonth() + 1<10 ? '0'+(date.getMonth() + 1):(date.getMonth() + 1); 
						var DD=date.getDate()<10 ? '0'+date.getDate():date.getDate(); 
						var hh=date.getHours()<10 ? '0'+date.getHours():date.getHours();
						var mm=date.getMinutes()<10 ? '0'+date.getMinutes():date.getMinutes(); 
						var ss=date.getSeconds()<10 ? '0'+date.getSeconds():date.getSeconds();
						return YY+"-"+MM+"-"+DD+" "+hh+":"+mm+":"+ss; 
					}
				}
			})
		</script>
	</body>
</html>
